package frontend;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.dyno.visual.swing.layouts.Constraints;
import org.dyno.visual.swing.layouts.GroupLayout;
import org.dyno.visual.swing.layouts.Leading;



public class CommunityDialog extends JDialog {


	//VARIABLES
	private static final long serialVersionUID = 1L;

	private String image;
	private BoardFrame boardFrame;
	private JButton okButton;
	private JLabel backgroundImage;
	private static final String PREFERRED_LOOK_AND_FEEL = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";



	//CONSTRUCTORS
	public CommunityDialog() {
		initComponents();
	}
	
	public CommunityDialog(BoardFrame parent, String title, String image) {
		super(parent, title, true);
		this.image=image;
		this.boardFrame = parent;
		initComponents();
	}

	private void initComponents() {
		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		addWindowListener(new WindowAdapter() {
		    public void windowClosing(WindowEvent we) {
		    }
		});
		
		setLocationRelativeTo(this.boardFrame);
		setLocation(175,225);
		setFont(new Font("Dialog", Font.PLAIN, 12));
		setBackground(Color.white);
		setResizable(false);
		setForeground(Color.black);
		setLayout(new GroupLayout());
		add(initOkButton(), new Constraints(new Leading(324, 76, 10, 10), new Leading(269, 10, 10)));
		add(initBackgroundImage(), new Constraints(new Leading(0, 6, 6), new Leading(0, 6, 6)));
		setSize(415, 330);
	}

	private JButton initOkButton() {
		if (okButton == null) {
			okButton = new JButton();
			okButton.setText("OK");
			okButton.addActionListener(new ActionListener() {
	
				public void actionPerformed(ActionEvent event) {
					okActionActionPerformed(event);
				}
			});
		}
		return okButton;
	}
	private JLabel initBackgroundImage() {
		if (backgroundImage == null) {
			backgroundImage = new JLabel();
			backgroundImage.setIcon(new ImageIcon(getClass().getResource("/images/communityChest/" + this.image)));
		}
		return backgroundImage;
	}

	private static void installLnF() {
		try {
			String lnfClassname = PREFERRED_LOOK_AND_FEEL;
			if (lnfClassname == null)
				lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
			UIManager.setLookAndFeel(lnfClassname);
		} catch (Exception e) {
			System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
					+ " on this platform:" + e.getMessage());
		}
	}

	/**
	 * Main entry of the class.
	 * Note: This class is only created so that you can easily preview the result at runtime.
	 * It is not expected to be managed by the designer.
	 * You can modify it as you like.
	 */
	public static void main(String[] args) {
		installLnF();
		SwingUtilities.invokeLater(new Runnable() {
			@Override
			public void run() {
				CommunityDialog dialog = new CommunityDialog();
				dialog.setDefaultCloseOperation(ChanceDialog.DO_NOTHING_ON_CLOSE);
				dialog.setTitle("EventDialog");
				dialog.setLocationRelativeTo(null);
				dialog.getContentPane().setPreferredSize(dialog.getSize());
				dialog.pack();
				dialog.setVisible(true);
			}
		});
	}

	private void okActionActionPerformed(ActionEvent event) {
		this.dispose();
	}

}
